
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[EBAS_SP_GEM_LICENS_INFO]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[EBAS_SP_GEM_LICENS_INFO]
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE [DBO].[EBAS_SP_GEM_LICENS_INFO] 
	@licensTil varchar(255),
	@licensNr varchar(255),
	@licensType varchar(255),
	@slutDato datetime,
	@verifikation varchar(255) = ''	
WITH ENCRYPTION	
AS
	DECLARE @guid uniqueidentifier

	SET NOCOUNT ON	

	-- DELETE FROM EBAS_LICENS WHERE GUID <> @guid
	DELETE FROM EBAS_LICENS WHERE LICENS_TYPE = 'TRIAL'
	DELETE FROM EBAS_LICENS WHERE LICENS_TYPE = @licensType

	SET @guid = NEWID()

	INSERT INTO EBAS_LICENS (GUID, LICENS_TIL, LICENS_NUMMER, LICENS_TYPE, SLUT_DATO, VERIFIKATION)
	VALUES (@guid, @licensTil, @licensNr, @licensType, @slutDato, @verifikation)
		
	SELECT GUID, LICENS_TIL, LICENS_NUMMER, LICENS_TYPE, SLUT_DATO, VERIFIKATION, SALT
	FROM EBAS_LICENS
	WHERE GUID = @guid
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
